<?php

namespace Common;

/**
 * Controller
 *  控制器基类
 *
 *
 * @author	夏立军
 * @email	m17269@163.com
 * @time	2020年11月16日 10:33:45
 */
abstract class Controller
{
    protected $data;
    protected $controller_name;
    protected $view_name;
    protected $template_dir;

    public function __construct($controller_name, $view_name)
    {
        $this->controller_name = $controller_name;
        $this->view_name = $view_name;
        // 模板的位置
        $this->template_dir = APP::getInstance()->base_dir . '/templates';
    }

    public function assign($key, $value)
    {
        $this->data[$key] = $value;
    }

    function display($file = '')
    {
        if (empty($file)) {
            $file = strtolower($this->controller_name) . '/' . $this->view_name . '.php';
        }
        $path = $this->template_dir . '/' . $file;
        /**
         * 将数值解开
         */
        extract($this->data);
        include BASEDIR . $path;
    }
}
